home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.1.5 / components / nsDefaultCLH.js < prev    next >
Text File  |  2009-11-09  |  6KB  |  202 lines

  1. //@line 38 "/build/buildd/xulrunner-1.9.1-1.9.1.5+nobinonly/build-tree/mozilla/toolkit/components/nsDefaultCLH.js"
  2.  
  3. const nsISupports              = Components.interfaces.nsISupports;
  4.  
  5. const nsICategoryManager       = Components.interfaces.nsICategoryManager;
  6. const nsIComponentRegistrar    = Components.interfaces.nsIComponentRegistrar;
  7. const nsICommandLine           = Components.interfaces.nsICommandLine;
  8. const nsICommandLineHandler    = Components.interfaces.nsICommandLineHandler;
  9. const nsIFactory               = Components.interfaces.nsIFactory;
  10. const nsIModule                = Components.interfaces.nsIModule;
  11. const nsIPrefBranch            = Components.interfaces.nsIPrefBranch;
  12. const nsISupportsString        = Components.interfaces.nsISupportsString;
  13. const nsIWindowWatcher         = Components.interfaces.nsIWindowWatcher;
  14. const nsIProperties            = Components.interfaces.nsIProperties;
  15. const nsIFile                  = Components.interfaces.nsIFile;
  16. const nsISimpleEnumerator      = Components.interfaces.nsISimpleEnumerator;
  17.  
  18. /**
  19.  * This file provides a generic default command-line handler.
  20.  *
  21.  * It opens the chrome window specified by the pref "toolkit.defaultChromeURI"
  22.  * with the flags specified by the pref "toolkit.defaultChromeFeatures"
  23.  * or "chrome,dialog=no,all" is it is not available.
  24.  * The arguments passed to the window are the nsICommandLine instance.
  25.  *
  26.  * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
  27.  */
  28.  
  29. function getDirectoryService()
  30. {
  31.   return Components.classes["@mozilla.org/file/directory_service;1"]
  32.                    .getService(nsIProperties);
  33. }
  34.  
  35. var nsDefaultCLH = {
  36.   /* nsISupports */
  37.  
  38.   QueryInterface : function clh_QI(iid) {
  39.     if (iid.equals(nsICommandLineHandler) ||
  40.         iid.equals(nsIFactory) ||
  41.         iid.equals(nsISupports))
  42.       return this;
  43.  
  44.     throw Components.results.NS_ERROR_NO_INTERFACE;
  45.   },
  46.  
  47.   /* nsICommandLineHandler */
  48.  
  49.   handle : function clh_handle(cmdLine) {
  50.     var printDir;
  51.     while (printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false)) {
  52.       var out = "print-xpcom-dir(\"" + printDir + "\"): ";
  53.       try {
  54.         out += getDirectoryService().get(printDir, nsIFile).path;
  55.       }
  56.       catch (e) {
  57.         out += "<Not Provided>";
  58.       }
  59.  
  60.       dump(out + "\n");
  61.       Components.utils.reportError(out);
  62.     }
  63.  
  64.     var printDirList;
  65.     while (printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist",
  66.                                                       false)) {
  67.       out = "print-xpcom-dirlist(\"" + printDirList + "\"): ";
  68.       try {
  69.         var list = getDirectoryService().get(printDirList,
  70.                                              nsISimpleEnumerator);
  71.         while (list.hasMoreElements())
  72.           out += list.getNext().QueryInterface(nsIFile).path + ";";
  73.       }
  74.       catch (e) {
  75.         out += "<Not Provided>";
  76.       }
  77.  
  78.       dump(out + "\n");
  79.       Components.utils.reportError(out);
  80.     }
  81.     
  82.     if (cmdLine.handleFlag("silent", false)) {
  83.       cmdLine.preventDefault = true;
  84.     }
  85.  
  86.     if (cmdLine.preventDefault)
  87.       return;
  88.  
  89.     var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  90.                           .getService(nsIPrefBranch);
  91.  
  92.     try {
  93.       var singletonWindowType =
  94.                               prefs.getCharPref("toolkit.singletonWindowType");
  95.       var windowMediator =
  96.                 Components.classes["@mozilla.org/appshell/window-mediator;1"]
  97.                           .getService(Components.interfaces.nsIWindowMediator);
  98.  
  99.       var win = windowMediator.getMostRecentWindow(singletonWindowType);
  100.       if (win) {
  101.         win.focus();
  102.         cmdLine.preventDefault = true;
  103.       return;
  104.       }
  105.     }
  106.     catch (e) { }
  107.  
  108.     // if the pref is missing, ignore the exception 
  109.     try {
  110.       var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
  111.  
  112.       var flags = "chrome,dialog=no,all";
  113.       try {
  114.         flags = prefs.getCharPref("toolkit.defaultChromeFeatures");
  115.       }
  116.       catch (e) { }
  117.  
  118.       var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  119.                             .getService(nsIWindowWatcher);
  120.       wwatch.openWindow(null, chromeURI, "_blank",
  121.                         flags, cmdLine);
  122.     }
  123.     catch (e) { }
  124.   },
  125.  
  126.   helpInfo : "",
  127.  
  128.   /* nsIFactory */
  129.  
  130.   createInstance : function mdh_CI(outer, iid) {
  131.     if (outer != null)
  132.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  133.  
  134.     return this.QueryInterface(iid);
  135.   },
  136.  
  137.   lockFactory : function mdh_lock(lock) {
  138.     /* no-op */
  139.   }
  140. };
  141.  
  142. const clh_contractID = "@mozilla.org/toolkit/default-clh;1";
  143. const clh_CID = Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}");
  144.  
  145. var Module = {
  146.   /* nsISupports */
  147.  
  148.   QueryInterface : function mod_QI(iid) {
  149.     if (iid.equals(nsIModule) ||
  150.         iid.equals(nsISupports))
  151.       return this;
  152.  
  153.     throw Components.results.NS_ERROR_NO_INTERFACE;
  154.   },
  155.  
  156.   /* nsIModule */
  157.  
  158.   getClassObject : function mod_gch(compMgr, cid, iid) {
  159.     if (cid.equals(clh_CID))
  160.       return nsDefaultCLH.QueryInterface(iid);
  161.  
  162.     throw components.results.NS_ERROR_FAILURE;
  163.   },
  164.  
  165.   registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
  166.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  167.  
  168.     compReg.registerFactoryLocation(clh_CID,
  169.                                     "nsDefaultCLH",
  170.                                     clh_contractID,
  171.                                     fileSpec,
  172.                                     location,
  173.                                     type);
  174.  
  175.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  176.                            .getService(nsICategoryManager);
  177.  
  178.     catMan.addCategoryEntry("command-line-handler",
  179.                             "y-default",
  180.                             clh_contractID, true, true);
  181.   },
  182.  
  183.   unregisterSelf : function mod_unreg(compMgr, location, type) {
  184.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  185.     compReg.unregisterFactoryLocation(clh_CID, location);
  186.  
  187.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  188.                            .getService(nsICategoryManager);
  189.  
  190.     catMan.deleteCategoryEntry("command-line-handler",
  191.                                "y-default");
  192.   },
  193.  
  194.   canUnload : function (compMgr) {
  195.     return true;
  196.   }
  197. };
  198.  
  199. function NSGetModule(compMgr, fileSpec) {
  200.   return Module;
  201. }
  202.